/**
 * 
 */
var Login = (function(){
	
	function ErrorMsg(str) {
        layer.open({
            style: '-webkit-box-shadow:0 0 10px rgba(0, 0, 0, .5); -moz-box-shadow:0 0 10px rgba(0, 0, 0, .5);  box-shadow:0 0 10px rgba(0, 0, 0, .5);color:#74787a;',
            content:'<div class="textcenter">' + str + '</div>',
            time: 2
        });
    }
	
	
	/**
	 * check login authCode
	 */
	var loginAuthCode = function(){
		
		/*仿刷新：检测是否存在cookie*/
	    if($.cookie("captcha")){
	        var count = $.cookie("captcha");
	        var btn = $('#btnSendCode');
	        btn.text(count+'秒后可重新获取').attr('disabled',true).css('cursor','not-allowed');
	        var resend = setInterval(function(){
	            count--;
	            if (count > 0){
	                btn.text(count+'秒后可重新获取').attr('disabled',true).css('cursor','not-allowed');
	                $.cookie("captcha", count, {path: '/', expires: (1/86400)*count});
	            }else {
	                clearInterval(resend);
	                btn.text("获取验证码").removeClass('disabled').removeAttr('disabled style');
	            }
	        }, 1000);
	    }

	    /*点击改变按钮状态，已经简略掉ajax发送短信验证的代码*/
	    $('#btnSendCode').click(function(){
	        var btn = $(this);
	        var count = 90;
	        
	        if($('#mobile').val() == '') {
	            ErrorMsg('请输入您的手机号码！');
	            return;
	        } else if($('#mobile').val().length != 11) {
	            ErrorMsg('请输入正确的手机号码！');
	            return;
	        }
	    	if($('#idCard').val() == '') {
	            ErrorMsg('请输入您的身份证号码！');
	            return;
	        }
	    	var idCard = $('#idCard').val();
	    	var	mobile = $('#mobile').val();
	    	var param = {};
	    	$.post("/auth/sendCode/" + idCard + "/" + mobile,param,function(result){
	    		if(result.code == 0){
	    			 var resend = setInterval(function(){
    		            count--;
    		            if (count > 0){
    		                btn.text(count+"秒后可重新获取");
    		                $.cookie("captcha", count, {path: '/', expires: (1/86400)*count});
    		            }else {
    		                clearInterval(resend);
    		                btn.text("获取验证码").removeAttr('disabled style');
    		            }
    		        }, 1000);
    		        btn.attr('disabled',true).css('cursor','not-allowed');
	    		}
	    		ErrorMsg(result.message);
	    	})
	       
	    });
	    
	}
	
	return {
		initAuthCodeTime : function(){
			loginAuthCode();
		}
	}
	
})();